<template>
  <div class="login">
    <div class="logo">
      <img :src="QINIU + 'avatar.png'" />
    </div>
    <div class="login-title">注册 zoang id</div>
    <div class="login-form">
      <div class="form-item">
        <div class="icon-pic">
          <img :src="QINIU + 'login_username_icon.png'" />
        </div>
        <input
          type="number"
          maxlength="11"
          placeholder="手机号"
          v-model="formData.username"
        />
      </div>
      <div class="form-item">
        <div class="icon-pic">
          <img :src="QINIU + 'login_password_icon.png'" />
        </div>
        <input type="password" placeholder="密码" v-model="formData.password" />
      </div>
      <div class="form-item">
        <div class="icon-pic">
          <img :src="QINIU + 'login_password_icon.png'" />
        </div>
        <input type="password" placeholder="验证码" v-model="formData.code" />
        <div class="item-code">发送验证码</div>
      </div>
    </div>
    <div class="login-btn" @click="doRegister">注册</div>
    <div class="login-footer">
      注册代表你已同意 <span>用户协议</span> 和 <span>隐私政策</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        username: "13361655235",
        password: "123456",
        code: "464",
      },
    };
  },
  methods: {
    doRegister() {
      if (this.formData.code) {
        if (this.formData.username.length >= 11 && this.formData.length !== 0) {
          this.$axios.post("/login/register", this.formData).then((res) => {
            if (res.data.code === 200) {
              this.$toast.success(res.data.msg);
              localStorage.setItem("token", res.data.data);
              this.$router.push("/my");
            } else {
              this.$toast.fail(res.data.msg);
            }
          });
        } else {
          this.$toast.fail("登录信息填写错误，请重新检查后提交");
        }
      }
    },
    // 跳转注册
    jump(path) {
      this.$router.push(path);
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  padding-top: 1.173333rem;
  .logo {
    text-align: center;
    padding-top: 1.733333rem;
    img {
      width: 2.32rem;
    }
  }
  .login-title {
    font-size: 0.586667rem;
    color: #362c2b;
    text-align: center;
    padding: 0.773333rem 0;
  }
  .login-form {
    .form-item {
      padding: 0.213333rem 0.88rem;
      display: flex;
      position: relative;
      .icon-pic {
        width: 1.173333rem;
        img {
          width: 100%;
          height: 102%;
        }
      }
      input {
        box-sizing: border-box;
        flex: 1;
        border: 1px solid #eeeeee;
        border-left: none;
        padding-left: 0.4rem;
        font-size: 0.4rem;
        color: #333;
      }
      .item-code {
        position: absolute;
        right: 1.2rem;
        top: 50%;
        transform: translateY(-50%);
        color: #3c6ed6;
      }
    }
    .form-link {
      text-align: right;
      font-size: 0.346667rem;
      color: #3c6ed6;
      padding: 0.213333rem 0.88rem;
    }
  }
  .login-btn {
    width: 8.213333rem;
    height: 0.96rem;
    line-height: 0.96rem;
    font-size: 0.36rem;
    border-radius: 0.1rem;
    margin: 0.26rem auto;
    background: linear-gradient(0deg, #4e7aef, #6a96f4);
    text-align: center;
    color: #fff;
  }
  .login-footer {
    text-align: center;
    color: #bebebe;
    position: absolute;
    bottom: 2.593333rem;
    left: 0;
    width: 100%;
    span {
      color: #3c6ed6;
    }
  }
}
</style>